package cn.wind.xboot.framework.filter;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import java.io.IOException;

/**
 * <p>Title: ServletInputStreamWrapper</p>
 * <p>Description: TODO</p>
 *
 * @author xukk
 * @version 1.0
 * @date 2018/8/21
 */

public class ServletInputStreamWrapper extends ServletInputStream {
    private byte[] data;
    private int idx = 0;

    public ServletInputStreamWrapper(byte[] data) {
        if(data == null) {
            data = new byte[0];
        }

        this.data = data;
    }
    @Override
    public int read() throws IOException {
        return this.idx == this.data.length?-1:this.data[this.idx++] & 255;
    }

    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public boolean isFinished() {
        return false;
    }

    @Override
    public void setReadListener(ReadListener readListener) {

    }
}
